<?php
namespace app\admin\controller;
use think\Db;
class Losemoney
{

    public function __construct(){
        Admin_auth();
    }

    public function index()
    {
        $where['type'] = 'seller';
        $pages = pages('losemoney',$where,input('get.page'));
        $data = Db::table("losemoney")->whereIn('aid', session('aid'))->where($where)->limit($pages['limit'])->order('id desc')->select();
        foreach ($data as $k => $v){
            $data[$k]['username'] = Db::table('seller')->whereIn('aid', session('aid'))->where('id',$v['uid'])->value('name');
        }
        return view('',['data'  => $data,'pages' => $pages['pages']]);
    }

    public function edit()
    {
        $id = request()->request('id');
        $page = input("get.page");
        Db::table('losemoney')->where('id',$id)->update(['status'=>1]);
        $uid = request()->request('uid');
        $money = Db::table('losemoney')->where('id',$id)->find();
        Db::table('seller')->where('id',$money['uid'])->setDec('losemoney',$money['money']);
        push(md5($uid),json_encode(['title'=>'提现处理','message'=>'您的提现已成功打款，请注意查收','type'=>1]),'seller');
        insert_message('seller',$uid,'提现处理','您的提现已成功打款，请注意查收',1);
        redirect(url('losemoney/index').'?page='.$page);
        exit;
    }

    public function del()
    {
        $id = input("get.id")?input("get.id"):0;
        $page = input("get.page");
        $uid = request()->request('uid');
        $user = Db::table('user')->where('id',$uid)->find();
        $money = $user['money']+$user['losemoney'];
        $losemoney = 0;
        Db::table("user")->where('id',$user['id'])->update(['money'=>$money,'losemoney'=>$losemoney]);
        push(md5($uid),json_encode(['title'=>'提现处理','message'=>'您的提现由于某种原因被拒绝','type'=>1]),'seller');
        insert_message('seller',$uid,'提现处理','您的提现由于某种原因被拒绝',1);
        Db::table("losemoney")->where('id',$id)->update(['status'=>3]);
        redirect(url('losemoney/index').'?page='.$page);
        exit;
    }


}